import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/AboutView.vue')
  }
]

const router = new VueRouter({
  routes
})
// 路由守卫
router.beforeEach((to,from,next)=>{
  if(to.path=="/"){
    next()
  }
  else{
    let token = window.sessionStorage.getItem("homeTableData");
    if(token){
      next()
    }else{
      next("/")
    }
  }
})

export default router
